package storm;


import bean.ordertail;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class spliteFile2 {
    public static ordertail getOrdersBean(String orderInfo) {
        //System.out.println(orderInfo);
        ordertail order = new ordertail();
        String content = orderInfo;
        Pattern p;
        Matcher m;
//        //orderdetailid
//        String regStr1 = "orderdetailid...\\w*";//16
//        p = Pattern.compile(regStr1);
//        m = p.matcher(content);
//        if(m.find()){
//            String temp = m.group(0);
//            int l = temp.length();
//            order.setOrderDetailId(temp.substring(16,l));
//            //System.out.println(temp.substring(11,l));
//        }else{
//            order.setOrderDetailId("");
//            //.out.println("no");
//        }
        //orderid
        String regStr2 = "orderid...\\w*";//10
        p = Pattern.compile(regStr2);
        m = p.matcher(content);
        if(m.find()){
            String temp = m.group(0);
            int l = temp.length();
            order.setOrderId(temp.substring(10,l));
            //System.out.println(temp.substring(10,l));
        }else{
            order.setOrderId("");
            //System.out.println("no");
        }
//        //sender
//        String regStr3 = "sender...[\\u4e00-\\u9fa5]*";//9
//        p = Pattern.compile(regStr3);
//        m = p.matcher(content);
//        if(m.find()){
//            String temp = m.group(0);
//            int l = temp.length();
//            order.setSender(temp.substring(9,l));
//            //System.out.println(temp.substring(12,l-2));
//        }else{
//            order.setSender("");
//            //System.out.println("no");
//        }
        //sendplace
        String regStr4 = "sendplace...[\\u4e00-\\u9fa5]*";//12
        p = Pattern.compile(regStr4);
        m = p.matcher(content);
        if(m.find()){
            String temp = m.group(0);
            int l = temp.length();
            order.setSendplace(temp.substring(12,l));
            //System.out.println(temp.substring(12,l));
        }else{
            order.setSendplace("");
            // System.out.println("no");
        }
        //recipient
        String regStr5 = "recipient...[\\u4e00-\\u9fa5]*";//12
        p = Pattern.compile(regStr5);
        m = p.matcher(content);
        if(m.find()){
            String temp = m.group(0);
            int l = temp.length();
            order.setRecipient(temp.substring(12,l));
            //System.out.println(temp.substring(11,l));
        }else{
            order.setRecipient("");
//            System.out.println("no");
        }
//        //receiveplace
//        String regStr6 = "receiveplace...[\\u4e00-\\u9fa5]*";//15
//        p = Pattern.compile(regStr6);
//        m = p.matcher(content);
//        if(m.find()){
//            String temp = m.group(0);
//            int l = temp.length();
//            order.setReceiveplace(temp.substring(15,l));
//            //System.out.println(temp.substring(13,l));
//        }else{
//            order.setReceiveplace("");
////            System.out.println("no");
//        }
        //methodofpayment
        String regStr7 = "methodofpayment...[\\u4e00-\\u9fa5]*";//18
        p = Pattern.compile(regStr7);
        m = p.matcher(content);
        if(m.find()){
            String temp = m.group(0);
            int l = temp.length();
            order.setMethodofpayment(temp.substring(18,l));
            // System.out.println(temp.substring(13,l));
        }else{
            order.setMethodofpayment("");
//            System.out.println("no");
        }
//        //paytime
//        String regStr8 = "paytime...\\d{4}-\\d{2}-\\d{2}.\\d{2}:\\d{2}:\\d{2}";//10
//        p = Pattern.compile(regStr8);
//        m = p.matcher(content);
//        if(m.find()){
//            String temp = m.group(0);
//            int l = temp.length();
//            order.setPaytime(temp.substring(10,l));
//            //System.out.println(temp.substring(5,l-2));
//        }else{
//            order.setPaytime("");
////            System.out.println("no");
//        }
//        //freight
//        String regStr9 = "freight...\\d*\\.\\d*";//10
//        p = Pattern.compile(regStr9);
//        m = p.matcher(content);
//        if(m.find()){
//            String temp = m.group(0);
//            int l = temp.length();
//            order.setFreight(Double.valueOf(temp.substring(10,l)));
//            //System.out.println(temp.substring(5,l-2));
//        }else{
//            order.setFreight(0);
////            System.out.println("no");
//        }
        //total
        String regStr10 = "total...\\d*\\.\\d*";//8
        p = Pattern.compile(regStr10);
        m = p.matcher(content);
        if(m.find()){
            String temp = m.group(0);
            int l = temp.length();
            order.setTotal(Double.valueOf(temp.substring(8,l)));
            //System.out.println(temp.substring(5,l-2));
        }else{
            order.setTotal(0);
//            System.out.println("no");
        }
        return order;

    }
}
